package com.xcl.service.impl;

import com.xcl.mapper.DebtMapper;
import com.xcl.mapper.FinancingMapper;
import com.xcl.mapper.OutsourcingCostMapper;
import com.xcl.pojo.Debt;
import com.xcl.service.DebtServiceInter;
import com.zzg.entity.Finance;
import com.zzg.entity.Financing;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DebtServiceImpl
 * @Description 欠款核销服务层实现类
 * @Author: xiaochaolei
 * @date 2021/7/29 9:30
 * @Version 1. 0
 */
@Service
public class DebtServiceImpl implements DebtServiceInter {
    @Autowired
    DebtMapper debtMapper;


    @Autowired
    OutsourcingCostMapper outsourcingCostMapper;
    @Autowired
    FinancingMapper financingMapper;
    @Override
    public List<Debt> getALLDebt(String consignDate,String tms_name,String forwardingUnit,String sub_id,String verification) {
        List<Debt> allDebtOne = debtMapper.getAllDebtOne(consignDate,tms_name,forwardingUnit,sub_id,verification);
        List<Debt> allDebtThree = debtMapper.getAllDebtThree(consignDate,tms_name,forwardingUnit,sub_id,verification);
        List<Debt> allDebtTwo = debtMapper.getAllDebtTwo(consignDate,tms_name,forwardingUnit,sub_id,verification);
        for (int i = 0; i < allDebtThree.size(); i++) {
            allDebtOne.add(allDebtThree.get(i));
        }
        for (int i = 0; i < allDebtTwo.size(); i++) {
            allDebtOne.add(allDebtTwo.get(i));
        }
        return allDebtOne;
    }

    @Override
    public List<Debt> getALLDebtBylimit(int page, int limit,String consignDate,String tms_name,String forwardingUnit,String sub_id,String verification) {
        List<Debt> allDebtOneByLimit = debtMapper.getAllDebtOneByLimit((page - 1) * limit, limit,consignDate,tms_name,forwardingUnit,sub_id,verification);
        List<Debt> allDebtTwoeByLimit = debtMapper.getAllDebtTwoeByLimit((page - 1) * limit, limit,consignDate,tms_name,forwardingUnit,sub_id,verification);
        List<Debt> allDebtThreeByLimit = debtMapper.getAllDebtThreeByLimit((page - 1) * limit, limit,consignDate,tms_name,forwardingUnit,sub_id,verification);
        for (int i = 0; i < allDebtTwoeByLimit.size(); i++) {
            allDebtOneByLimit.add(allDebtTwoeByLimit.get(i));
        }
        for (int i = 0; i < allDebtThreeByLimit.size(); i++) {
            allDebtOneByLimit.add(allDebtThreeByLimit.get(i));
        }
        return allDebtOneByLimit;
    }

    @Override
    public int updateVerification(String id) {
        return debtMapper.updateVerification(id);
    }

    @Override
    public int updateZuoFei(String id) {
        //查询出财务信息
        Finance financingById = debtMapper.getFinancingById(id);
        //修改为true
        debtMapper.updateVerification(id);
        //修改财务信息
        financingById.setOrderstatus("已结清");
        financingMapper.updateFinancing(financingById);
        //修改财务详细信息
        return outsourcingCostMapper.updateCostBreakdown(financingById.getCostbreakdownId());
    }
}
